//
//  CreatOrderViewController.m
//  Doctors
//
//  Created by 王森 on 16/4/22.
//  Copyright © 2016年 王森. All rights reserved.
//

#import "CreatOrderViewController.h"
#import "UIView+BottomAddLine.h"
#import "UIButton+Block.h"
@interface CreatOrderViewController ()

@end

@implementation CreatOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addLeftBackBtn:nil];
    self.title=@"创建订单";

    [self.moneyTextfield addBottomLine:SCREEN_WIDTH  HeadIndent:16 tailIndent:0 color:nil];
    [self.markView  addBottomLine:SCREEN_WIDTH  HeadIndent:16 tailIndent:0 color:nil];
    self.creatBtn.layer.cornerRadius=5;
    
  
    RACSignal *yanZheng=[self.moneyText.rac_textSignal map:^id(NSString *str) {
        return  @([self isValidMoney:str]);
        
        
    }];
                         
                         
                         
       [yanZheng subscribeNext:^(NSNumber*signupActiv) {
        self.creatBtn.enabled=[signupActiv boolValue];
        
            self.creatBtn.backgroundColor=[signupActiv boolValue]?UIColorFromRGB(0x00ccc2):UIColorFromRGB(0xe5e5e5);
        
    }];
                         
    
    [self.creatBtn addActionHandler:^(NSInteger tag) {
    
        
        NSMutableDictionary *dic=[NSMutableDictionary dictionary];
        [dic setObject:self.userId forKey:@"userId"];
        [dic setObject:self.receiptId forKey:@"receiptId"];
        [dic setObject:[self getArtisanId] forKey:@"artisanId"];
        [dic setObject:[NSString stringWithFormat:@"%.0f",[self.moneyText.text floatValue]*100] forKey:@"amount"];
        [dic setObject:self.markText.text forKey:@"remark"];
        
        

        [self requestApiWithUrl:@"/order/createOrder" dictionary:dic isCache:NO success:^(id responseObject) {
            
            [self showSuccess:@"开单成功"];
            [self.navigationController popToRootViewControllerAnimated:YES];
            
            NSLog(@"----%@",responseObject);
            
        } faild:^(NSError *error) {
            NSLog(@"%@",error)
            ;
            [self showFailed:@"请求出错了"];
        }];
        
        
        
    }];
    
    
    // Do any additional setup after loading the view from its nib.
}

- (BOOL)isValidMoney:(NSString *)money {
    return money.length >=1;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
